package com.yogee.topseller.activity.my;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yogee.core.base.HttpActivity;
import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.topseller.R;
import com.yogee.topseller.adapter.YJLSRvAdapter;
import com.yogee.topseller.bean.SelectCommissionBean;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.layout.TXLCLayout;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.AppUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MyCommissionActivity extends HttpActivity {
    @BindView(R.id.my_commission_yj_tv)
    TextView myCommissionYjTv;
    @BindView(R.id.my_commission_ktyj_tv)
    TextView myCommissionKtyjTv;
    @BindView(R.id.my_commission_yjls_rv)
    RecyclerView myCommissionYjlsRv;
    @BindView(R.id.my_commission_txlc_layout)
    TXLCLayout myCommissionTxlcLayout;
    @BindView(R.id.my_commission_yjls_tv)
    TextView myCommissionYjlsTv;
    @BindView(R.id.my_commission_yjls_v)
    View myCommissionYjlsV;
    @BindView(R.id.my_commission_txlc_tv)
    TextView myCommissionTxlcTv;
    @BindView(R.id.my_commission_txlc_v)
    View myCommissionTxlcV;
    @BindView(R.id.my_commission_title_layout)
    TitleLayout titleLayout;
    @BindView(R.id.my_commission_yjls_rl)
    RelativeLayout yjlsRl;
    @BindView(R.id.my_commission_txlc_rl)
    RelativeLayout txlcRl;
    private YJLSRvAdapter yjlsRvAdapter;
    private List<SelectCommissionBean.CommListBean> bean;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_commission;
    }

    @Override    
    protected void initView() {
        titleLayout.setActivity(this);
        titleLayout.setTitle("我的佣金");
//        titleLayout.setBgColor(Color.parseColor("#ffffff"));
//        titleLayout.setTitleTvColor(getResources().getColor(R.color.colorStyle));
//        titleLayout.setBackImg(R.mipmap.personal_back);

        bean = new ArrayList<>();
        yjlsRvAdapter = new YJLSRvAdapter(this, bean);
        myCommissionYjlsRv.setLayoutManager(new LinearLayoutManager(this));
        myCommissionYjlsRv.setAdapter(yjlsRvAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        selectCommission(AppUtil.getUserId(this));
    }

    @OnClick({R.id.my_commission_txsq_tv, R.id.my_commission_yjls_rl, R.id.my_commission_txlc_rl})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.my_commission_txsq_tv://提现申请
                startActivity(new Intent(this, TakeCashActivity.class));
                break;
            case R.id.my_commission_yjls_rl://佣金流水
                myCommissionYjlsV.setVisibility(View.VISIBLE);
                myCommissionTxlcV.setVisibility(View.GONE);
                myCommissionTxlcLayout.setVisibility(View.GONE);
                myCommissionYjlsRv.setVisibility(View.VISIBLE);
                yjlsRl.setBackgroundColor(Color.parseColor("#ffffff"));
                txlcRl.setBackgroundColor(Color.parseColor("#f7f7f7"));
                break;
            case R.id.my_commission_txlc_rl://提现流程
                myCommissionYjlsV.setVisibility(View.GONE);
                myCommissionTxlcV.setVisibility(View.VISIBLE);
                myCommissionTxlcLayout.setVisibility(View.VISIBLE);
                myCommissionYjlsRv.setVisibility(View.GONE);
                yjlsRl.setBackgroundColor(Color.parseColor("#f7f7f7"));
                txlcRl.setBackgroundColor(Color.parseColor("#ffffff"));
                break;
        }
    }

    private void selectCommission(String userid) {
        HttpManager.getInstance().selectCommission("0", userid, "").compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<SelectCommissionBean>() {
            @Override
            public void onNext(SelectCommissionBean o) {
                bean = o.getCommList();
                yjlsRvAdapter.setList(bean);
                myCommissionYjTv.setText(o.getCommMoney());
                myCommissionKtyjTv.setText(o.getUnableMoney());
            }
        }, this));
    }

}